package com.leetcode.蓝桥杯.十一届国赛;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

import org.junit.Test;

public class 编程题6 {
	static int[][] p = { // 0 or 2 or 6 or 8
			{ 2, 3, 8 }, { 1, 4, 7 }, { 0, 5, 6 } };
	static int[][] p1 = { // 1 or 7
			{ 8, 3, 0 }, { 7, 4, 1 }, { 6, 5, 2 } };
	static int[][] p3 = { // 3 or 5
			{ 0, 5, 6 }, { 1, 4, 7 }, { 2, 3, 8 } };
	static int[][] p4 = { { 6, 5, 0 }, { 7, 4, 1 }, { 8, 3, 2 } };

	public static void main(String[] args) {
		Input input = new Input();
		int k = input.nextInt();
		System.out.println(k);
		long[][] a = new long[2][2];
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				a[i][j] = input.nextLong();
				System.out.println(a[i][j]);
			}
		}
		
		input.close();
	}

	public static long cal(int k) {
		return (long) (Math.pow(3, k) * Math.pow(3, k)) - 1;
	}

	public static long cal(int k, int x) {
		if (k == 1) {
			return x;
		}
		return x * cal(k - 1) - 1;
	}

	public static int getType(int x, int y, int type) {
		if (type == 0 || type == 2 || type == 6 || type == 8)
			return p[x][y];
		if (type == 1 || type == 7)
			return p1[x][y];
		if (type == 3 || type == 5)
			return p3[x][y];
		return p4[x][y];
	}

	public static long cal(int k, int x, int y, int type) {
		if (k == 1) {
			return getType(x, y, type);
		}
		int x1 = 0;
		if (x <= (Math.pow(3, k - 1) - 1))
			x1 = 0;
		else if (x <= (2 * Math.pow(3, k - 1) - 1))
			x1 = 1;
		else
			x1 = 2;
		int y1 = 0;
		if (y <= (Math.pow(3, k - 1) - 1))
			y1 = 0;
		else if (y <= (2 * Math.pow(3, k - 1) - 1))
			y1 = 1;
		else
			y1 = 2;
		long ans = 0;
		if (x1 != 0 && y1 != 0)
			ans = cal(k, getType(x1, y1, type) - 1);

		return 0;
	}

	@Test
	public void test() {
		System.out.println(cal(2, 7));
	}

	public static class Input {
		BufferedReader buf;
		StringTokenizer tok;

		Input() {
			buf = new BufferedReader(new InputStreamReader(System.in));
		}

		void close() {
			if (buf != null) {
				try {
					buf.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
		boolean hasNext() {
			while(tok == null || !tok.hasMoreElements()) {
				try {
					tok = new StringTokenizer(buf.readLine());
				} catch (IOException e) {
					return false;
				}
			}
			return true;
		}
		
		String next() {
			if(hasNext()) {
				return tok.nextToken();
			}
			return null;
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		String nextLine() {
			try {
				return buf.readLine();
			} catch (IOException e) {
				return null;
			}
		}
	}
}
